package com.ctvit.cch.web.controller;

import com.ctvit.cch.core.pojo.dto.hot.HotCategoryAddDTO;
import com.ctvit.cch.core.pojo.dto.hot.HotCategoryEditDTO;
import com.ctvit.cch.core.pojo.dto.hot.HotCategoryListDTO;
import com.ctvit.cch.core.service.IHotCategoryService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 热点分类Controller
 *
 * @author heyingcheng
 * @date 2025/7/19
 */
@RestController
@RequestMapping("/hot/category")
public class HotCategoryController extends BaseController {

    private final IHotCategoryService hotCategoryService;

    public HotCategoryController(IHotCategoryService hotCategoryService) {
        this.hotCategoryService = hotCategoryService;
    }

    /**
     * 查询热点分类列表
     *
     * @param dto 列表参数
     * @return {@link AjaxResult } 列表数据
     */
    @PreAuthorize("@ss.hasPermi('hot:category:list')")
    @PostMapping("/list")
    public AjaxResult list(HotCategoryListDTO dto) {
        return success(hotCategoryService.list(dto));
    }

    /**
     * 获取热点分类详细信息
     *
     * @param id ID
     * @return {@link AjaxResult } 详细信息
     */
    @PreAuthorize("@ss.hasPermi('hot:category:get')")
    @PostMapping(value = "/{id}")
    public AjaxResult get(@PathVariable String id) {
        return success(hotCategoryService.get(id));
    }

    /**
     * 新增热点分类
     *
     * @param dto 新增参数
     * @return {@link AjaxResult } 新增结果
     */
    @PreAuthorize("@ss.hasPermi('hot:category:add')")
    @Log(title = "热点分类", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody @Validated HotCategoryAddDTO dto) {
        return toAjax(hotCategoryService.add(dto));
    }

    /**
     * 修改热点分类
     *
     * @param dto 修改参数
     * @return {@link AjaxResult } 修改结果
     */
    @PreAuthorize("@ss.hasPermi('hot:category:edit')")
    @Log(title = "热点分类", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody @Validated HotCategoryEditDTO dto) {
        return toAjax(hotCategoryService.edit(dto));
    }

    /**
     * 删除热点分类
     *
     * @param ids ID集合
     * @return {@link AjaxResult } 删除结果
     */
    @PreAuthorize("@ss.hasPermi('hot:category:remove')")
    @Log(title = "热点分类", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    public AjaxResult remove(@RequestBody List<String> ids) {
        return toAjax(hotCategoryService.removeBatchByIds(ids));
    }

    /**
     * 查询热点榜单分类列表
     *
     * @return {@link AjaxResult } 列表数据
     */
    @PreAuthorize("@ss.hasPermi('hot:category:record')")
    @PostMapping("/record")
    public AjaxResult record() {
        return success(hotCategoryService.record());
    }

    /**
     * 查询全部分类列表
     *
     * @return {@link AjaxResult } 列表数据
     */
    @PreAuthorize("@ss.hasPermi('hot:category:list')")
    @PostMapping("/all")
    public AjaxResult all() {
        return success(hotCategoryService.all());
    }

    /**
     * 查询我的分类列表
     *
     * @return {@link AjaxResult } 列表数据
     */
    @PreAuthorize("@ss.hasPermi('hot:category:list')")
    @PostMapping("/my")
    public AjaxResult my() {
        return success(hotCategoryService.my());
    }

}
